﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;

    public class EquipAdvanceConfig extends Object
    {
        private var _map:Dictionary;
        private static var _instance:EquipAdvanceConfig;

        public function EquipAdvanceConfig()
        {
            this._map = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" EquipAdvanceConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TEquipAdvance = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TEquipAdvance();
                _loc_2.id = _loc_3.id;
                _loc_2.recordType = _loc_3.recordType;
                _loc_2.suitGroup = _loc_3.suitGroup;
                _loc_2.targetSuitGroup = _loc_3.targetSuitGroup;
                _loc_2.consumeMoney = _loc_3.consumeMoney;
                _loc_2.consumeItem = _loc_3.consumeItem;
                _loc_2.equipAttackDefense = _loc_3.equipAttackDefense;
                _loc_2.equipLevel = _loc_3.equipLevel;
                _loc_2.equipQuality = _loc_3.equipQuality;
                _loc_2.qualityAddPercent = _loc_3.qualityAddPercent;
                _loc_2.isWeapon = _loc_3.isWeapon;
                this._map[_loc_2.id] = _loc_2;
            }
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_equip_advance.json");
            this.write(_loc_1);
            return;
        }// end function

        public function getPercentByQual(param1:int) : int
        {
            var _loc_2:TEquipAdvance = null;
            for each (_loc_2 in this._map)
            {
                
                if (_loc_2.recordType == "QualityAddPercent" && _loc_2.equipQuality == param1)
                {
                    return _loc_2.qualityAddPercent;
                }
            }
            return 0;
        }// end function

        public function getInfo(param1:int, param2:int, param3:int) : TEquipAdvance
        {
            var _loc_4:TEquipAdvance = null;
            for each (_loc_4 in this._map)
            {
                
                if (_loc_4.equipLevel == param1 && _loc_4.equipQuality == param2 && _loc_4.equipAttackDefense == param3 && _loc_4.recordType == "QualityAdvance")
                {
                    return _loc_4;
                }
            }
            return null;
        }// end function

        public function getColorInfo(param1:int, param2:int) : TEquipAdvance
        {
            var _loc_3:TEquipAdvance = null;
            for each (_loc_3 in this._map)
            {
                
                if (_loc_3.recordType == "ColorAdvance" && _loc_3.suitGroup == param1 && _loc_3.equipAttackDefense == param2)
                {
                    return _loc_3;
                }
            }
            return null;
        }// end function

        public function getTargetSuitGroup(param1:int) : int
        {
            var _loc_2:int = 0;
            var _loc_3:TEquipAdvance = null;
            for each (_loc_3 in this._map)
            {
                
                if (_loc_3.suitGroup == param1)
                {
                    _loc_2 = _loc_3.targetSuitGroup;
                }
            }
            return _loc_2;
        }// end function

        public function getConsumeMoneyByLevel(param1:int) : int
        {
            var _loc_3:TEquipAdvance = null;
            var _loc_2:* = param1 / 10 * 10;
            if (_loc_2 == 0 || _loc_2 == 1)
            {
                _loc_2 = 1;
            }
            for each (_loc_3 in this._map)
            {
                
                if (_loc_3.recordType == "EquipTransfer" && _loc_3.equipLevel == _loc_2)
                {
                    return _loc_3.consumeMoney;
                }
            }
            return 0;
        }// end function

        public function getQualityLimitLevel(param1:int) : int
        {
            var _loc_2:TEquipAdvance = null;
            for each (_loc_2 in this._map)
            {
                
                if (_loc_2.recordType == "qualityLimited" && _loc_2.equipLevel == param1)
                {
                    return _loc_2.equipQuality;
                }
            }
            return 0;
        }// end function

        public static function get instance() : EquipAdvanceConfig
        {
            if (_instance == null)
            {
                _instance = new EquipAdvanceConfig;
            }
            return _instance;
        }// end function

    }
}
